<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="lib/react.development.js"></script>
    <script src="lib/react-dom.development.js"></script>
    <script src="lib/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
</body>
<script type="text/babel">
    const root = ReactDOM.createRoot(document.querySelector("#root"));
    class App extends React.Component{
        state = {
            num:1
        }
        shouldComponentUpdate(nextProps,nextState){
            // 当前实例下的状态还未发生更新
            console.log("1-shouldComponentUpdate",this.state.num,nextState.num);
            return false;
        }
        UNSAFE_componentWillUpdate(nextProps,nextState){
            console.log("2-UNSAFE_componentWillUpdate",this.state.num,nextState.num)
        }
        render(){
            // 数据状态更新完毕
            console.log("3-render",this.state.num)
            return (
                <div>
                    <button onClick={()=>{
                        // this.setState({
                        //     num:100
                        // })

                        this.state.num = 99;
                        this.forceUpdate();// 强制更新
                    }}>{this.state.num}</button>
                </div>
            )
        }
        componentDidUpdate(prevProps,prevState){
            console.log("4-componentDidUpdate",this.state.num,prevState.num,document.querySelector("button").innerText)
        }
    }
    root.render((
        <App></App>
    ))
</script>
</html>